const { ApiResponse, tokenMiddleware } = require('./api_response')
const router = require('express').Router()
const wss = require('../server/wssServer')

// 通知
router.post('/wsNotify', async (req, res) => {
    let apiRes = new ApiResponse(res);
    var str = JSON.stringify({
        "msg": req.body.msg,
        "type": "systemInfo"
    });
    wss.send(req.body.wsId,str)
    apiRes.success(true, '发送成功')
})

// 获取所有session链接
router.get('/allSession', async (req, res) => {
    let apiRes = new ApiResponse(res);
    let allSessions = [];
    wss.clients.forEach(function each(client) {
        allSessions.push(client.clientId)
    });
    apiRes.success(allSessions, '发送成功')
})

module.exports = router